package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.shop.bo.VipBO;
import com.junzhiit.nengji.shop.dao.VipDAO;
import com.junzhiit.nengji.shop.model.Vip;

@Repository
public class VipDAOImpl extends AbstractBaseDAO<Vip> implements VipDAO {

	@Override
	public List<Vip> findAll(int pageNumber, int maxPageRow) {
		StringBuffer sql = new StringBuffer();
		sql.append(" select * from vip where is_delete = ? ");

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());

		sql.append(" order by created_time desc");

		return super.queryForPagingList(sql.toString(), Vip.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getTotalCount() {
		StringBuffer sql = new StringBuffer();
		sql.append(" select count(*) from vip where is_delete = ?");

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());

		return super.queryForInt(sql.toString(), param);

	}

	@Override
	public Vip getVipByIdentity(Integer identity) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from vip where is_delete = ?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(identity != null){
			sql.append(" and identity = ?");
			params.setInt(identity);
		}
		return super.query(sql.toString(),Vip.class,params);
	}

	@Override
	public List<VipBO> getVipName() {
		StringBuffer sql = new StringBuffer();
		sql.append("select id,identity from vip where is_delete = ?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		
		return super.queryForList(sql.toString(),VipBO.class,params);
	}
}
